package com.hb.trade.server.project.opening.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hb.core.pojo.project.opening.dto.OpeningBidTenderDTO;
import com.hb.core.pojo.project.opening.entity.OpeningBidTender;
import com.hb.trade.server.project.opening.service.OpeningBidTenderService;
import org.fzzn.core.model.msg.Message;
import org.fzzn.core.util.MsgUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Description:开标大厅投标人记录表 前端控制器
 *
 * @author: fengbin
 * @date: 2022/2/24 10:48
 */
@RestController
public class OpeningBidTenderController {

    protected final OpeningBidTenderService openingBidTenderService;

    public OpeningBidTenderController(OpeningBidTenderService openingBidTenderService) {
        this.openingBidTenderService = openingBidTenderService;
    }

    /**
     * Description: 根据标段id获取该标段下的投标人名称（二轮报价处使用）
     * @author: fengbin
     * @date: 2022/2/24 10:32
     * @param sectionId
     @return: java.util.List<java.lang.Long>
     */
    @GetMapping("/openingBidTender/lsitBidderNameBySectionId")
    public Message<List<String>> lsitBidderNameBySectionId(Long sectionId) {
        List<String> longs = openingBidTenderService.listBidderNameBySectionId(sectionId);
        return MsgUtil.success(longs);
    }


    /**
     * 根据标段id查询解密成功的投标人
     *
     * @author yuezheng
     * @param sectionId
     * @return List<OpeningBidTender>
     * @date 2022/4/18 1:30 PM
     */
    @PostMapping("/openingBidTender/listBidderDecryptBySectionId")
    public Message<List<OpeningBidTender>> listBidderDecryptBySectionId(Long sectionId) {
        QueryWrapper<OpeningBidTender> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .select(OpeningBidTender::getId,OpeningBidTender::getSectionId,OpeningBidTender::getBidderId)
                .eq(OpeningBidTender::getSectionId,sectionId)
                .eq(OpeningBidTender::getDecryptFlag, 1);
        List<OpeningBidTender> list = this.openingBidTenderService.list(queryWrapper);
        return MsgUtil.success(list);
    }


    /**
     * @Description: 查询未签章或确认的投标人 query 1 未签章 2 未确认
     *
     * @author yuezheng
     * @param openingBidTenderDTO
     * @return org.fzzn.core.model.msg.Message<java.util.List<com.hb.core.pojo.project.opening.entity.OpeningBidTender>>
     * @date 2022/6/20 16:49
     */
    @PostMapping("/openingBidTender/listByNotDecryptOrConfirm")
    public Message<List<OpeningBidTender>> listByNotDecryptOrConfirm(@RequestBody OpeningBidTenderDTO openingBidTenderDTO) {
        if (openingBidTenderDTO.getOpeningBidInfoId() == null) {
            return MsgUtil.fail("缺少必要参数");
        }
        List<OpeningBidTender> result = this.openingBidTenderService.listByNotDecryptOrConfirm(openingBidTenderDTO);
        return MsgUtil.success(result);
    }
}



